package cn.com.thingo.shyintelligent.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.th.opensdk.openapi.CurtainInfo;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.thingo.shyintelligent.R;

public class CurtainListAdapter extends RecyclerView.Adapter<CurtainListAdapter.ViewHolder> {
    private List<CurtainInfo> list;
    private Context context;

    public CurtainListAdapter(List<CurtainInfo> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_curtain_list, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        final CurtainInfo curtainInfo = list.get(position);
        holder.tvName.setText(curtainInfo.getDeviceName());
        holder.ivOpen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                curtainInfo.open();
            }
        });
        holder.ivStop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                curtainInfo.stop();
            }
        });
        holder.ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                curtainInfo.close();
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.curtain_name)
        TextView tvName;
        @BindView(R.id.curtain_open)
        ImageView ivOpen;
        @BindView(R.id.curtain_stop)
        ImageView ivStop;
        @BindView(R.id.curtain_close)
        ImageView ivClose;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
